package com.dhy.builder;

import java.nio.charset.StandardCharsets;

import static com.dhy.constants.CommandTypeConstants.*;

/**
 * @author 大忽悠
 * @create 2022/5/29 20:24
 */
public class StandardCommandBuilder implements CommandBuilder{
    /**
     * 通过传入的参数数组构造最终的命令字符串,然后发送给服务端
     */
    @Override
    public String buildCommand(String... args) {
        StringBuilder res=new StringBuilder();
        res.append(ARRAY).append(args.length).append(NEWLINE);
        for (String arg : args) {
            res.append(MULTIPLY_LINE).append(arg.getBytes(StandardCharsets.UTF_8).length)
                    .append(NEWLINE).append(arg).append(NEWLINE);
        }
        return res.toString();
    }
}
